<template>
  <el-aside :width="width">
    <el-menu
      class="el-menu-vertical-demo"
      background-color="#333"
      text-color="#fff"
      :collapse="isCollapse"
      :collapse-transition="false"
      :default-active="activeMenu"
    >
      <h3 v-show="!isCollapse">通用后台管理</h3>
      <h3 v-show="isCollapse">后台</h3>
      <!-- @open="handleOpen"
    @close="handleClose" -->
      <!-- <el-menu-item
        v-for="item in noChilren"
        :key="item.path"
        :index="item.path"
        @click="handleMenu(item)"
      >
        <el-icon><component :is="item.icon" class="icons"></component></el-icon>
        {{ item.label }}</el-menu-item
      > -->
      <el-menu-item
        v-for="item in noChilren"
        :key="item.path"
        :index="item.path"
        @click="handleMenu(item)"
      >
        <el-icon><component :is="item.icon" class="icons"></component></el-icon>
        <template #title>{{ item.label }}</template>
      </el-menu-item>
      <el-sub-menu
        v-for="item in hasChilren"
        :key="item.path"
        :index="item.path"
         @click="handleMenu(item)"
      >
        <template #title>
          <!-- <el-icon><location /></el-icon> -->
          <el-icon>
            <component :is="item.icon" class="icons"></component>
          </el-icon>
          <span>{{ item.label }}</span>
        </template>

        <el-menu-item-group :title="item.label">
          <el-menu-item
            v-for="(subItem, subIndex) in item.children"
            :index="subItem.path"
            :key="subIndex"
            @click="handleMenu(subItem)"
            ><component :is="subItem.icon" class="icons"></component>
            <span>{{ subItem.label }}</span></el-menu-item
          >
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script setup>
import { ref, computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useAllDataStore } from "@/stores";
const router = useRouter();
const route = useRoute();
const store = useAllDataStore();
// const width = ref("200px");
// const list = ref([
//   {
//     path: "/home",
//     name: "home",
//     label: "首页",
//     icon: "house",
//     url: "Home",
//   },
//   {
//     path: "/mall",
//     name: "mall",
//     label: "商品管理",
//     icon: "video-play",
//     url: "Mall",
//   },
//   {
//     path: "/user",
//     name: "user",
//     label: "用户管理",
//     icon: "user",
//     url: "User",
//   },
//   {
//     path: "other",
//     label: "其他",
//     icon: "location",
//     children: [
//       {
//         path: "page1",
//         name: "page1",
//         label: "页面1",
//         icon: "setting",
//         url: "Page1",
//       },
//       {
//         path: "page2",
//         name: "page2",
//         label: "页面2",
//         icon: "setting",
//         url: "Page2",
//       },
//     ],
//   },
// ]);
const list = computed(() => {
  return store.state.menuList;
});
const noChilren = computed(() => {
  return list.value.filter((item) => !item.children);
});
const hasChilren = computed(() => {
  return list.value.filter((item) => item.children);
});
const isCollapse = computed(() => {
  return store.state.isCollapse;
});
const width = computed(() => {
  return isCollapse.value ? "64px" : "180px";
});
const handleMenu = (item) => {
  router.push({ path: item.path });
  store.selectMenu(item);
};

const activeMenu = computed(() => {
  return route.path;
});
</script>

<style lang="less" scoped>
.el-menu {
  border-right: none;
  h3 {
    line-height: 60px;
    color: #fff;
    text-align: center;
  }
}
.el-aside {
  height: 100vh !important;
  background-color: #333;
  .el-menu-item {
    width: 100%;
    text-align: center;
  }
}
.icons {
  width: 18px;
  height: 18px;
  margin-right: 5px;
}
</style>
